<template>
<div class="wrapper">
  <div class="headTop">
    <head title="Payment details"></head>
  </div>
  <div style="flex:1">
    <web
      class="web"
      v-if="!finshPage"
      ref="webview"
      :src="pageUrl"
      @pagestart="onPageStart"
      @pagefinish="onPageFinish"
      @error="onError"
      @receivedtitle="onReceivedTitle"
    ></web>
    <div class="icon" v-if="finshPage">
      <text class="iconfont">&#xe60d;</text>
      <text class="status">Payment successful</text>
      <text class="btn" @click="returnpage">Return</text>
      <!-- <text class="btn">View orders</text> -->
    </div>
  </div>
</div>
</template>
<script>
export default {
  data() {
    return {
      pageUrl: "https://www.empirise.com/mall/public/web/pay.html?",
      orderId: "",
      finshPage: false
    };
  },
  methods: {
    backPage() {
      if (this.canGoBack) {
        var webview = weex.requireModule("webview");
        webview.goBack(this.$refs.webview);
      } else {
      }
    },
    onLoad(param) {
      if (param && param.param) {
        return false;
      }
      if (param && param.id) {
        this.orderId = param.id;
        let activity = "";
        if (param.activity) {
          activity = "111";
        }
        this.pageUrl = `https://www.empirise.com/mall/public/web/pay.html?id=${param.id}&amount=${param.amount}&userId=${param.userId}&isWeb=app&activity=${activity}`;
      } else {
        this.back();
      }
    },
    onPageStart: function(e) {
      if (e.url.indexOf("payresult.html") > -1) {
        this.finshPage = true;
        // this.push("root:app/pay/success.js", { id: this.orderId });
      }
    },
    onPageFinish: function(e) {
      this.canGoBack = e.canGoBack;
    },
    onError: function(e) {},

    returnpage() {
      var navigator = weex.requireModule("navigator");
      if (!this.isWeb) {
        navigator.backTo("A");
      } else {
        this.push("root:index.js");
      }
    },
    onReceivedTitle: function(e) {}
  }
};
</script>
<style  scope>
.wrapper {
  background-color: #303030;
  flex: 1;
}
.leftBox {
  align-items: center;
  flex-direction: row;
  flex: 1;
  justify-content: center;
}
.arricon {
  font-size: 40px;
  font-family: iconfont;
  color: #fff;
}
.headTop {
}
.web {
  flex: 1;
}

.icon {
  width: 750px;
  flex: 1;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

.iconfont {
  font-family: iconfont;
  font-size: 300px;
  color: #4ab440;
}

.status {
  color: #4ab440;
  font-size: 34px;
  margin-top: 50px;
  margin-bottom: 160px;
}

.btn {
  width: 400px;
  height: 80px;
  line-height: 80px;
  border-radius: 80px;
  background-color: #303030;
  color: #fff;
  text-align: center;
  font-size: 30px;
  margin-top: 88px;
}
</style>